using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Comteck.Utils;
using DevExpress.Accessibility;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Drawing;
using DevExpress.XtraEditors.Registrator;
using DevExpress.XtraEditors.Repository;

namespace Comteck.Winforms.Controls {
  /// <summary>
  /// 
  /// </summary>
  [ToolboxItem(true)]
  public class MyDateEdit : DateEdit {
    /// <summary>
    /// 
    /// </summary>
    static MyDateEdit() {
      RepositoryItemMyDateEdit.Register();
    }

    /// <summary>
    /// ctor
    /// </summary>
    public MyDateEdit() {
      this.Properties.DisplayFormat.FormatString = DateTimeHelper.GetFormatString(EnumDateTimeFormat.YYYYMMDD);
      this.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
      this.Properties.EditFormat.FormatString = DateTimeHelper.GetFormatString(EnumDateTimeFormat.YYYYMMDD);
      this.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
      this.Properties.EditMask = DateTimeHelper.GetFormatString(EnumDateTimeFormat.YYYYMMDD);

      this.Properties.CalendarView = CalendarView.Classic;
      this.Properties.AllowMouseWheel = false;
      //this.Properties.ShowClear = false;
      //this.EnterMoveNextControl = true;
    }

    #region fields

    /// <summary>
    /// 
    /// </summary>
    public override string EditorTypeName => RepositoryItemMyDateEdit.EditorName;

    /// <summary>
    /// 
    /// </summary>
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public new RepositoryItemMyDateEdit Properties => base.Properties as RepositoryItemMyDateEdit;

    //
    // 摘要:
    //     Gets or sets whether focus is moved to the next control (according to the tab
    //     order) when an end-user presses ENTER.
    [DefaultValue(true)]
    //[DevExpressXtraEditorsLocalizedDescriptionAttribute("BaseEditEnterMoveNextControl")]
    [DXCategory("Behavior")]
    public override bool EnterMoveNextControl { get; set; } = true;

    #endregion
  }

  /// <summary>
  /// 
  /// </summary>
  [DXCategory("Properties")]
  [UserRepositoryItem("Register")]
  //[ToolboxItem(true)]
  public class RepositoryItemMyDateEdit : RepositoryItemDateEdit {

    /// <summary>
    /// 
    /// </summary>
    static RepositoryItemMyDateEdit() {
      Register();
    }

    /// <summary>
    /// 
    /// </summary>
    public RepositoryItemMyDateEdit() {
      this.AllowMouseWheel = false;


      this.DisplayFormat.FormatString = DateTimeHelper.GetFormatString(EnumDateTimeFormat.YYYYMMDD);
      this.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
      this.EditFormat.FormatString = DateTimeHelper.GetFormatString(EnumDateTimeFormat.YYYYMMDD);
      this.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
      this.EditMask = DateTimeHelper.GetFormatString(EnumDateTimeFormat.YYYYMMDD);

      this.CalendarView = CalendarView.Classic;
      this.AllowMouseWheel = false;
    }

    /// <summary>
    /// 
    /// </summary>
    internal const string EditorName = nameof(MyDateEdit);

    /// <summary>
    /// 
    /// </summary>
    public override string EditorTypeName => EditorName;

    ///// <summary>
    ///// 
    ///// </summary>
    //[DefaultValue(false)]
    //[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    //[DXCategory("Behavior")]
    //[RefreshProperties(RefreshProperties.All)]
    //public override bool ShowClear { get; set; } = false;

    /// <summary>
    /// 
    /// </summary>
    public static void Register() {
      EditorRegistrationInfo.Default.Editors.Add(
        new EditorClassInfo(
          EditorName, // 
          typeof(MyDateEdit),
          typeof(RepositoryItemMyDateEdit),
          typeof(DevExpress.XtraEditors.ViewInfo.DateEditViewInfo),
          new TimeSpanEditPainter(),
          true,
          null,
          typeof(DateEditTextAccessible)));
    }
  }

}
